package com.blb.service.impl;


import com.blb.dao.IPetDao;
import com.blb.dao.impl.PetDaoImpl;
import com.blb.pojo.Pet;
import com.blb.dao.IPetDao;
import com.blb.dao.impl.PetDaoImpl;
import com.blb.pojo.Page;
import com.blb.pojo.Pet;
import com.blb.service.IPetService;

import java.sql.SQLException;
import java.sql.SQLException;

import java.util.List;

public class PetServiceImpl implements IPetService {
    private static IPetDao petDao = new PetDaoImpl();

    //寵物更新
    @Override
    public void update(Pet pet) throws SQLException, ClassNotFoundException {
        petDao.update(pet);
    }

    //宠物修改界面
    @Override
    public Pet updatePage(int id) throws Exception {
        return petDao.getPetById(id);
    }

    @Override
    public Page<Pet> selectPageByName(String name, int size, int page) throws Exception {
        List<Pet> pets = petDao.selectPageByName(name, size, page);
        int count = petDao.count(name);
        return new Page<Pet>(page,size,pets,count);
    }

    @Override
    public void delete(int id) throws SQLException, ClassNotFoundException {
        petDao.delete(id);
    }


    @Override
    public void add(Pet pet) throws Exception {
        petDao.insertPet(pet);
    }

}
